/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Interface.InterfaceOrganization;
import Pojo.Organization;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author olegk
 */
public class DaoOrganization implements InterfaceOrganization {

    @Override
    public boolean register(Session session, Organization organization) throws Exception {
        session.save(organization);
        return true;
    }

    @Override
    public List<Organization> getAll(Session session) throws Exception {
        String hql="from Organization";
        Query query=session.createQuery(hql);        
        List<Organization> listOrganization =(List<Organization>) query.list();        
        return listOrganization;
    }

    @Override
    public boolean update(Session session, Organization organization) throws Exception {
        session.update(organization);
        return true;
    }

    @Override
    public boolean delete(Session session, Organization organization) throws Exception {
        session.delete(organization);
        return true;
    }

    @Override
    public Organization selectOrganizationName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }
        Organization organization=(Organization) query.uniqueResult();        
        return organization;
    }

    @Override
    public List<Organization> selectListOrganizationName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }       
        List<Organization> listOrganization =(List<Organization>) query.list();        
        return listOrganization;
    }
    
}
